// D3D9RenderUnit.h

#ifndef __D3D9RENDERUNIT_H__
#define __D3D9RENDERUNIT_H__

class CD3D9VertexBuffer;
class CD3D9IndexBuffer;
class CD3D9RenderUnit
{
public:
	struct TMaterial
	{
		// material and texture
		D3DMATERIAL9* m_pMtrl;
		IDirect3DTexture9* m_pTex;
	};
private:
	// buffer
	CD3D9VertexBuffer* m_pVB;
	CD3D9IndexBuffer* m_pIB;

	// declaration
	IDirect3DVertexDeclaration9* m_pDecl;

	// Material
	TMaterial* m_arrayMaterial;

	// draw primitive
	int m_nBaseVertexIndex;
	int m_nMinIndex;
	int m_nNumVertices;
	int m_nPrimitiveCount;
	int m_nStartIndex;
	int m_nSizeofVertex;

public:
	// non-const method
	void SetVB(CD3D9VertexBuffer* pVB);
	void SetIB(CD3D9IndexBuffer* pIB);
	void SetDecl(LPDIRECT3DVERTEXDECLARATION9 pDecl);

	void SetNumVertices(int nNumVertices);
	void SetMinIndex(int nMinIndex);
	void SetStartIndex(int nStartIndex);
	void SetBaseVertexIndex(int nBaseVertexIndex);
	void SetPrimitiveCount(int nNumTri);
	void SetVertexSize(int nSizeVertex);

	void UpdateVB(size_t offset, size_t length, const void* pSource);
	void UpdateIB(size_t offset, size_t length, const void *pSource);

	// const method
	D3DMATERIAL9* GetMtrl(void) const;
	IDirect3DTexture9* GetTex(void) const;
	IDirect3DIndexBuffer9* GetIB(void) const;
	IDirect3DVertexBuffer9* GetVB(void) const;
	IDirect3DVertexDeclaration9* GetDecl(void) const;

	int GetNumVertices(void) const;
	int GetMinIndex(void) const;
	int GetStartIndex(void) const;
	int GetBaseVertexIndex(void) const;
	int GetPrimitiveCount(void) const;
	int GetVertexSize(void) const;

public:
	CD3D9RenderUnit(void);
	virtual ~CD3D9RenderUnit();
};

#endif